package dao;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import model.Menu;
import model.MenuItem;

public class TxtMenuDAO implements IMenuDAO {

	public Menu getMenu() {
		Menu newMenu = new Menu();
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(
					new FileInputStream("files\\menu.txt")));
			String stringDate = in.readLine();
			SimpleDateFormat dateFormat = new SimpleDateFormat(
					"yyyy.MM.dd HH:mm:ss z");
			newMenu.setDate(dateFormat.parse(stringDate));
			while (in.ready()) {
				String s = in.readLine();
				String[] f = s.split(":", 3);
				MenuItem item = new MenuItem();
				item.setName(f[0]);
				item.setPrice(new BigDecimal(f[1]));
				item.setIngredients(f[2]);
				newMenu.addNewItem(item);
			}
			in.close();
		} catch (IOException e) {
		} catch (ParseException e) {
		}
		return newMenu;
	}

}
